/**
 * Created by liuhui
 */
define([ 'adminapp', 'bootstrap-daterangepicker', 'spinner'], function ($app) {

    var prvview_tpl = Handlebars.compile($(g.preview_template).html());

    $app.navactive('ktv');

    $('#spinner1').spinner();

    $app.formvalidator({
        'ktv.name'       : {
            required : true,
            maxlength: 160
        },
        'ktv.remark': {
            maxlength: 500
        },
        'ktv.rule'  : {
            maxlength: 500
        }

    }, 'ktvform');

    $app.single_uploader({
        'uploader'       : g.ctx + 'file/up?dpi=bacvtity',
        'buttonText'     : '点击上传项目图片',
        'width'           : 120,
        'hideButton'      : true,
        'height'          : 20
    },'logo_image_btn');

    $app.uploader({
        'buttonText'     : '点击上传图片', width: 140,
        queueSizeLimit   : 100,
        'onUploadSuccess': function (file, data, response) {
            var jsonData = eval('(' + data + ')');
            if (jsonData['status'] == 'OK') {
                var attachement_path = jsonData['data'];
                var $moPrictures = $('#mo_prictures');
                var val = $moPrictures.val();
                if (val) {
                    $moPrictures.val((val + ",") + attachement_path);
                } else {
                    $moPrictures.val(attachement_path);
                }
                $('#pricture-grid').append(prvview_tpl({ctx: g.ctx, data: attachement_path.replace('.', '.thumbnail.'), preview: attachement_path}))

            }
        }
    }, 'prictureAttachmentUpload');

    $('#pricture-grid').on('a.mix-link[data-hook="remove-pic"]', 'click', function (e) {
        e.preventDefault();
        var $this = $(this);
        $this.closest('div.mix').remove();
        return false;
    });

    return {};
});